package com.uzai.console.web.fd;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.fd.fdfollowconfig.FdFollowConfigDto;
import com.uzai.console.dto.fd.fdfollowconfig.FdFollowConfigIdDto;
import com.uzai.console.dto.fd.fdfollowconfig.FdFollowConfigQuery;
import com.uzai.console.dto.fd.fdfollowconfig.FdFollowConfigStatusDto;
import com.uzai.console.dto.remoteapi.RefreshDownloadImgGroupWxidListDto;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.fd.FdFollowConfigService;
import com.uzai.console.vo.fd.fdfollowconfig.FdFollowConfigVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 发单自动跟发配置
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "自动跟发配置",tags = "个人微信|发单|自动跟发配置")
@ApiSort(104)
@RestController
public class FdFollowConfigController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(FdFollowConfigController.class);

    @Autowired
    private FdFollowConfigService fdFollowConfigService;

    @ApiOperation(value = "分页查询自动跟发配置列表", notes = "分页查询自动跟发配置列表", response = FdFollowConfigVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/fdFollowConfig/findFdFollowConfigList")
    public Object findFdFollowConfigList(@RequestBody FdFollowConfigQuery fdFollowConfigQuery){
        return fdFollowConfigService.findFdFollowConfigList(fdFollowConfigQuery);
    }

    @SystemLogType(model = SystemModelEnum.FdFollowConfig, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加自动跟发配置", notes = "添加自动跟发配置")
    @ApiOperationSupport(order = 2)
    @PostMapping("/fdFollowConfig/addFdFollowConfig")
    public Object addFdFollowConfig(@RequestBody FdFollowConfigDto fdFollowConfigDto){
        fdFollowConfigService.addFdFollowConfig(fdFollowConfigDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.FdFollowConfig, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "编辑自动跟发配置", notes = "编辑自动跟发配置" )
    @ApiOperationSupport(order = 3)
    @PostMapping("/fdFollowConfig/updateFdFollowConfig")
    public Object updateFdFollowConfig(@RequestBody FdFollowConfigDto fdFollowConfigDto){
        fdFollowConfigService.updateFdFollowConfig(fdFollowConfigDto);

        //刷新需要下载大图的群列表缓存
        RefreshDownloadImgGroupWxidListDto refreshDownloadImgGroupWxidListDto = new RefreshDownloadImgGroupWxidListDto();
        refreshDownloadImgGroupWxidListDto.setMerId(fdFollowConfigDto.getMerId());
        fdFollowConfigService.refreshDownloadImgGroupWxidList(refreshDownloadImgGroupWxidListDto);

        return true;
    }

    @SystemLogType(model = SystemModelEnum.FdFollowConfig, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除", notes = "删除")
    @ApiOperationSupport(order = 4)
    @PostMapping("/fdFollowConfig/deleteFdFollowConfig")
    public Object deleteFdFollowConfig(@RequestBody FdFollowConfigIdDto fdFollowConfigIdDto){
        fdFollowConfigService.deleteFdFollowConfig(fdFollowConfigIdDto);

        //刷新需要下载大图的群列表缓存
        RefreshDownloadImgGroupWxidListDto refreshDownloadImgGroupWxidListDto = new RefreshDownloadImgGroupWxidListDto();
        refreshDownloadImgGroupWxidListDto.setMerId(fdFollowConfigIdDto.getMerId());
        fdFollowConfigService.refreshDownloadImgGroupWxidList(refreshDownloadImgGroupWxidListDto);

        return true;
    }

    @ApiOperation(value = "查询自动跟发配置详情", notes = "查询自动跟发配置详情", response = FdFollowConfigVo.class)
    @ApiOperationSupport(order = 5)
    @PostMapping("/fdFollowConfig/findFdFollowConfig")
    public Object findFdFollowConfig(@RequestBody FdFollowConfigIdDto fdFollowConfigIdDto){
        return fdFollowConfigService.findFdFollowConfig(fdFollowConfigIdDto);
    }

    @ApiOperation(value = "开启关闭自动跟发配置", notes = "开启关闭自动跟发配置", response = Boolean.class)
    @ApiOperationSupport(order = 6)
    @PostMapping("/fdFollowConfig/updateStatus")
    public Object updateStatus(@RequestBody FdFollowConfigStatusDto fdFollowConfigStatusDto){
        fdFollowConfigService.updateStatus(fdFollowConfigStatusDto);

        //刷新需要下载大图的群列表缓存
        RefreshDownloadImgGroupWxidListDto refreshDownloadImgGroupWxidListDto = new RefreshDownloadImgGroupWxidListDto();
        refreshDownloadImgGroupWxidListDto.setMerId(fdFollowConfigStatusDto.getMerId());
        fdFollowConfigService.refreshDownloadImgGroupWxidList(refreshDownloadImgGroupWxidListDto);
        return true;
    }

}
